package com.ido.babyshow.action;

import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import javax.annotation.Resource;
import javax.servlet.ServletContext;

import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.ido.babyshow.model.Catalog;
import com.ido.babyshow.model.Photo;
import com.ido.babyshow.model.SecCatalog;
import com.ido.babyshow.model.Catalog.CataComparetor;
import com.ido.babyshow.service.impl.CatalogService;
import com.ido.babyshow.service.impl.SecCatalogService;
import com.opensymphony.xwork2.ActionSupport;

/**
 * 首页action处理
 * @author luo sq
 *
 */
@Component
@Scope("prototype")
public class HomeAction extends ActionSupport
{
    @Resource
    private CatalogService catalogService;    
    @Resource
    private SecCatalogService secCatalogService;
    
    private Map<Catalog,List<SecCatalog>> catalogMap=new TreeMap<Catalog,List<SecCatalog>>(new CataComparetor());
    
    /**所有栏目信息**/
    private List<Catalog> catalogList;  
    
    private List<SecCatalog> secCatalogList;
    
    /**model大图**/
    private Photo modelPhoto;   
    
    public Map<Catalog, List<SecCatalog>> getCatalogMap()
    {
        return catalogMap;
    }

    public List<Catalog> getCatalogList()
    {
        return catalogList;
    }    

    public List<SecCatalog> getSecCatalogList()
    {
        return secCatalogList;
    }

    public Photo getModelPhoto()
    {
        return modelPhoto;
    }


    public void setCatalogService(CatalogService catalogService)
    {
        this.catalogService = catalogService;
    }
    
    
    public String home(){
        
         catalogList=catalogService.selectAllCatalog();   
         Map<Integer,List<SecCatalog>> tempMap=secCatalogService.selectList();
         for(Catalog catalog:catalogList){
             catalogMap.put(catalog,tempMap.get(catalog.getId()));
         }
         ServletContext context = ServletActionContext.getServletContext();
         context.setAttribute("catalogMap", catalogMap);
         context.setAttribute("catalogList", catalogList);
        return SUCCESS;
    }
}
